package com.ffapp.rainmonitorcustom.map;

import android.app.Activity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ffapp.rainmonitorcustom.R;
import com.ffapp.rainmonitorcustom.bean.BaseListData;
import com.ffapp.rainmonitorcustom.bean.BaseListDataListBean;
import com.ffapp.rainmonitorcustom.bean.DeviceListData;
import com.flyco.dialog.widget.NormalDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PopDetail extends NormalDialog {


    Activity mActivity;

    BaseListDataListBean mListBean;

    @BindView(R.id.recyclerview)
    RecyclerView recyclerView;
    @BindView(R.id.text_title)
    TextView text_title;
    DeviceListData mDeviceListData;

    public PopDetail(Activity context,DeviceListData data) {
        super(context);
//            setCanceledOnTouchOutside(false);
        mActivity = context;
        this.mDeviceListData = data;

        mListBean = new BaseListDataListBean();
        mListBean.getList().add(new BaseListData(mDeviceListData.getCapacity()+"千瓦","装机容量"));
        mListBean.getList().add(new BaseListData(mDeviceListData.getStlc(),"地理位置"));
        mListBean.getList().add(new BaseListData(mDeviceListData.getWorkername(),"联系人"));
        mListBean.getList().add(new BaseListData(mDeviceListData.getWorkerphone(),"联系电话"));
        mListBean.getList().add(new BaseListData(mDeviceListData.getWorkermobile(),"手机"));
        mListBean.getList().add(new BaseListData(mDeviceListData.getApprovedEcoFlow()+"㎥/s","核准生态流量"));
        mListBean.getList().add(new BaseListData(mDeviceListData.getApprovedEcoFlowModel_Str(),"生态流量模式"));
        mListBean.getList().add(new BaseListData(mDeviceListData.getDvraddr(),"IP地址"));
    }

    @Override
    public View onCreateView() {
//        return super.onCreateView();
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.map_pop_detail, null);
        ButterKnife.bind(this, inflate);
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        return inflate;
    }

    @Override
    public void setUiBeforShow() {
        text_title.setText(mDeviceListData.getStnm());
       recyclerView.setAdapter(new MyAdapterList());
    }



    @OnClick(R.id.img_close)
    void close() {
        dismiss();
    }
    @OnClick(R.id.btn_current_flow)
    void btnFlow() {
        mDeviceListData.save();
        mActivity.setResult(Activity.RESULT_OK);
        dismiss();
        mActivity.finish();
    }
    @OnClick(R.id.btn_current_video)
    void btnVideo() {
        dismiss();
    }


    public class MyAdapterList extends RecyclerView.Adapter<MyAdapterList.ViewHolder> {

        public MyAdapterList() {

        }

        //创建新View，被LayoutManager所调用
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_pop_detail_item, viewGroup, false);
            return new ViewHolder(view);
        }


        //将数据与界面进行绑定的操作
        @Override
        public void onBindViewHolder(ViewHolder viewHolder, int position) {
            BaseListData data = mListBean.getList().get(position);
            viewHolder.text_name.setText(TextUtils.isEmpty(data.getName())?"-":data.getName());
            viewHolder.text_value.setText(data.getId());

        }

        //获取数据的数量
        @Override
        public int getItemCount() {
            return mListBean == null ? 0 : mListBean.getList().size();
        }

        //自定义的ViewHolder，持有每个Item的的所有界面元素
        public class ViewHolder extends RecyclerView.ViewHolder {
            @BindView(R.id.list_item)
            public View list_item;
            @BindView(R.id.text_name)
            public TextView text_name;
            @BindView(R.id.text_value)
            public TextView text_value;


            public ViewHolder(View view) {
                super(view);
                ButterKnife.bind(this, view);
            }

        }
    }

}